{extend name="public/world"}
{block name="style"}{/block}
{block name="container"}
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-form" lay-filter="formSearch">
                    <div class="layui-field-box" style="padding:0;">
                        <div class="layui-form-item" style="margin-bottom:0">
                            <div class="layui-inline my-search">
                                <div class="layui-input-inline">
                                    <input type="text" name="name" value="" placeholder="按名称" autocomplete="off" class="layui-input" lay-filter="name">
                                </div>
                                <div class="layui-input-inline" style="width: 170px;">
                                    <button type="button" class="layui-btn layui-btn-sm layui-btn-radius layui-btn-primary" title="清除条件" style="padding: 0 8px" lay-submit lay-filter="reset"><i class="layui-icon" style="color:#009688;">&#xe640;</i></button>
                                    <button type="button" class="layui-btn layui-btn-sm layui-btn-radius" lay-submit lay-filter="search">搜索</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <table class="layui-hide" id="dataTable" lay-filter="dataTable"></table>
                <div class="" id="userBox" style="display: none;">
                    <blockquote class="layui-elem-quote" id="descBox" style="margin-top: 5px;margin-bottom: 0;padding: 0;line-height: 22px;border-left: 1px solid #009688;border-bottom: 1px solid #009688;"></blockquote>
                    <table class="layui-hide" id="userTable" lay-filter="userTable"></table>
                </div>
            </div>
        </div>
    </div>
{/block}
{block name="script"}
<script type="text/html" id="barDemo">
    {if isset($sonAuth['edit'])}
    <input type="checkbox" name="status" value="{{ d.status }}" lay-skin="switch" lay-filter="switchStatus" lay-text="启用|禁用" {{ d.status == 1 ? 'checked' : '' }} data-href="{:url('/erp.BasicsAgent/edit')}?id={{ d.id }}">
    <a href="{:url('/erp.BasicsAgent/edit')}?id={{ d.id }}" class="layui-btn layui-btn-xs j-iframe-pop" lxb-data="{width: '1060px', height: '550px'}" title="修改代理商">修改</a>
    {/if}
</script>
<script type="text/html" id="toolbar">
    <div class="layui-btn-group fl">
        {if isset($sonAuth['add'])}
        <a href="{:url('/erp.BasicsAgent/add')}" class="layui-btn layui-btn-xs layuiadmin-btn-admin j-iframe-pop" lxb-data="{width: '1060px', height: '550px'}" title="添加代理商">添加代理商</a>
        {/if}
    </div>
</script>
<script>
    layui.use(['form','table'], function() {
        var $ = layui.$
            , form = layui.form
            , table = layui.table;
        //渲染
        form.on('submit(search)', function(){
            tableIns.reload({
                where: form.val("formSearch"),
                page: {curr: 1}
            });
        });
        //头工具栏事件
        form.on('submit(reset)', function(){
            var searchs = form.val("formSearch");
            for (var i in searchs) {
                searchs[i] = '';
            }
            form.val("formSearch", searchs);
            tableIns.reload({
                where: form.val("formSearch"),
                page: {curr: 1}
            });
        });
        var tableIns = table.render({
            elem: '#dataTable'
            ,url: "{:url('/erp.BasicsAgent/index')}" //数据接口
            ,where: form.val("formSearch")
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,size: 'sm'
            ,limit: 10
            ,text: {
                none : '暂无代理商'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: false
            ,cols: [[ //表头
                {field: 'name', width: 220, title: '名称', fixed: 'left'}
                ,{field: 'z_type', width: 80, title: '合作类型'}
                ,{field: 'sys_type', width: 80, title: '企业/个人'}
                ,{field: 'phone', width: 100, title: '电话1'}
                ,{field: 'phone2', width: 100, title: '电话2'}
                ,{field: 'username', width: 100, title: '联系人'}
                ,{field: 'address', width: 120, title: '地域'}
                ,{field: 'detailed_address', width: 180, title: '详细地址'}
                ,{field: 'bank', width: 180, title: '缺省银行'}
                ,{field: 'bank_code', width: 180, title: '缺省账户'}
                ,{field: 'bank_name', width: 180, title: '缺省支行'}
                ,{fixed: 'right', width: 130, title: '操作', templet: '#barDemo'}
            ]]
        });
        table.on('row(dataTable)', function(obj){
            if($(obj.tr).hasClass('row-in')) {
                $(obj.tr).removeClass('row-in');
                $('#descBox').text('');
                table.render({
                    elem: '#userTable'
                    , cols: [[ //标题栏
                        {field: 'name', title: '姓名', width: 100}
                        , {field: 'position', title: '职位', width: 100}
                        , {field: 'phone', title: '电话', width: 100}
                        , {field: 'email', title: '邮箱', width: 150}
                        , {field: 'address', title: '地址', width: 160}
                        , {field: 'desc', title: '备注', width: 160}
                    ]]
                    , data: {}
                    , even: false
                    , size: 'sm'
                });
                $('#userBox').hide();
            } else {
                $(obj.tr).addClass('row-in').siblings('tr').removeClass('row-in');
                $('#descBox').text(obj.data.description);
                table.render({
                    elem: '#userTable'
                    , cols: [[ //标题栏
                        {field: 'name', title: '姓名', width: 100}
                        , {field: 'position', title: '职位', width: 100}
                        , {field: 'phone', title: '电话', width: 100}
                        , {field: 'email', title: '邮箱', width: 150}
                        , {field: 'address', title: '地址', width: 160}
                        , {field: 'desc', title: '备注', width: 160}
                    ]]
                    , data: obj.data.link_mans
                    , even: false
                    , size: 'sm'
                });
                $('#userBox').show();
            }
        });
    });
</script>
{/block}